package com.jed.xxh.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

import com.jed.xxh.R;
import com.jed.xxh.utils.ShareUtil;
import com.jed.xxh.utils.StaticClass;
import com.jed.xxh.utils.UtilTools;

/**
 * 项目名：MyApplication<br/>
 * 包名：  com.jed.xxh.ui<br/>
 * 作者：徐晓辉<br/>
 * 创建日期：2018/11/24 17:35<br/>
 * 描述：闪屏页<br/>
 */
public class SplashActivity extends AppCompatActivity {

    private TextView tv_splash;
    private Handler handler = new Handler() {


        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case StaticClass.HANDLER_SPLASH:
                    if (isFirst()) {
                        startActivity(new Intent(SplashActivity.this, GuideActivity.class));
                    } else {
                        startActivity(new Intent(SplashActivity.this, LoginActivity.class));
                    }
                    finish();
                    break;
            }
        }
    };


    /**
     * 1.延时2秒
     * 2.判断是否第一次运行APP
     * 3.自定义字体
     * 4.Activity主题
     *
     * @param savedInstanceState
     */
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        initView();

    }

    /**
     * 初始化
     */
    private void initView() {
        handler.sendEmptyMessageDelayed(StaticClass.HANDLER_SPLASH, 1000);

        tv_splash = findViewById(R.id.tv_splash);
        UtilTools.setFont(SplashActivity.this, tv_splash);


    }

    /**
     * 判断APP是否是第一次运行
     */
    private boolean isFirst() {
        Boolean isFirst = ShareUtil.getBoolean(StaticClass.SHARE_IS_FIRST, true);
        if (isFirst) {
            ShareUtil.putBoolean(StaticClass.SHARE_IS_FIRST, false);
            return true;
        } else {
            return false;
        }
    }

    /**
     * 禁用返回键
     */
    @Override
    public void onBackPressed() {
        super.onBackPressed();
    }
}
